#
# setw is short for set-window-option	
#
unbind ^b
set -g prefix ^x
bind a send-prefix

bind ^a last-window  #last-window
unbind '"'
bind - splitw -v # 分割成上下两个窗口
unbind %
bind | splitw -h # 分割成左右两个窗口
#Split window and remain current directory
bind | send-keys "~/sk-chang/config/split-tmux -h" \; send-keys "Enter"
bind - send-keys "~/sk-chang/config/split-tmux -v" \; send-keys "Enter"

#bind k selectp -U # 选择上窗格
#bind j selectp -D # 选择下窗格
#bind h selectp -L # 选择左窗格
#bind l selectp -R # 选择右窗格
#通过^o实现跳转，不需要以上几个

bind ^k resizep -U 10 # 更改window大小，跟选择窗格的设置相同，只是多加 Ctrl（Ctrl-k）
bind ^j resizep -D 10 # 同上
bind ^h resizep -L 10 # ...
bind ^l resizep -R 10 # ...

bind ^u swapp -U # 与上窗格交换 Ctrl-u
bind ^d swapp -D # 与下窗格交换 Ctrl-d

#resolve shortcuts conflict for emacs & emacs-like editor
bind ^c send-prefix \; send-keys "C-c"
bind ^s send-prefix \; send-keys "C-s"
bind ^f send-prefix \; send-keys "C-f"
bind ^w send-prefix \; send-keys "C-w"
bind u send-prefix \; send-keys "u"

#浏览，复制&粘贴（这样并没有直接复制到系统剪贴板中，而是tmux的buffer？？）
bind v copy-mode		#复制模式，可上下翻页，可复制 (C-x PageUp 貌似效果等同) (默认为C-x [) (像Emacs中那样选中文字按下 C-w 或 M-w 复制;按下q或C-c退出)
bind y paste-buffer		#粘贴（默认为C-x ])，注意C-v, C-y
#C-y, C-x y, C-v 粘贴的内容来自不同的buffer ....怎么样都来自clipboard

####################################################################################################
########## these functions implement in the tmux source code (modified, need xclip command) ########
#复制选中区域到系统剪贴板 (C-x C-w) (C-w还是普通的复制。。。有办法使用M-w代替C-x C-w吗？？？？)
#必须安装xclip命令
#first copy selection to buffer, then copy it to clipboard
#bind ^w send-keys "M-w" \; run "tmux show-buffer > log"
#below command is valid !
#bind ^w send-keys "M-w" \; run "tmux show-buffer | xclip -i -selection clipboard"
####################################################################################################



#set -g default-terminal "screen-256color" 	#it cause : sessions should be nested with care. unset $TMUX to force.

setw -g mode-keys emacs		#default is emacs 
setw -g xterm-keys on

set-window-option -g mode-mouse off # disable mouse

#utf8 support
set-window-option -g utf8 on
set -g status-utf8 on

# session (in shell ??)
#C-x s,选择attach的window (默认)

# new -s work 	#create a session named work (in shell: tmux new -s work)
# tmux attach -t work 	#attach it
# attach-session -t work
# new  -n WindowName Command
# new -s work
# attach-session -t work


bind -n S-Down neww 	# Shift-Down 新建窗口
bind -n S-Left prev 	# Shift-Left 上个窗口
bind -n S-Right next 	# Shift-Down 下个窗口


#status bar
set-option -g visual-activity on
set-window-option -g monitor-activity on
set-window-option -g automatic-rename on
#set -g status-right "#[fg=green]#(uptime.pl)#[default] • #[fg=green]#(cut -d ' ' -f 1-3 /proc/loadavg)#[default]"
set -g status-right "#(date +'%Y-%m-%d  %H:%M')"
set -g display-time 3000
#set -g status-bg default
set -g status-bg black
#set -g status-fg blue
set -g status-fg yellow
set-window-option -g window-status-current-attr bright,reverse
#set-window-option -g window-status-current-bg blue
#set-window-option -g window-status-current-fg black
set-window-option -g window-status-current-bg yellow
set-window-option -g window-status-current-fg black


#others & shortcuts
#Ctrl-x l (Move to the previously selected window)
#Ctrl-x w (List all windows / window numbers)
#Ctrl-x <window number> (Move to the specified window number, the default bindings are from 0 – 9)
#Ctrl-x q  (Show pane numbers, when the numbers show up type the key to goto that pane)

#scrolling with Shift-PageUp/Shift-PageDown

#Start tmux on every shell login
#Simply add the following line of bash code to your .bashrc before your aliases; the code for other shells is very similar:
#[[ $TERM != "screen" ]] && tmux && exit


#others:
#C-x t		#显示时间
#C-x ?		#显示所有快捷键，相当于tmux list-keys （直接在运行了tmux的xterm中执行）
#paste-buffer	: 粘贴通过C/M-w复制的文字


#bind ^w run "leafpad"	#C-x C-w时执行shell命令leafpad (run is short for run-shell)

